package com.yanqu.road.server.manger.activity.recycle;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.ActivityItemRecycleData;
import com.yanqu.road.entity.activity.suitang.config.SuiTangCampBoxConfig;
import com.yanqu.road.entity.activity.suitang.config.SuiTangConfigSync;
import com.yanqu.road.entity.activity.tongbing.config.TongBingCampBoxConfig;
import com.yanqu.road.entity.activity.tongbing.config.TongBingConfig;
import com.yanqu.road.entity.activity.toyhouse.config.ToyHouseConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.player.UserBagItem;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.suitang.SuiTangMgr;
import com.yanqu.road.server.manger.activity.tongbing.TongBingMgr;
import com.yanqu.road.server.manger.activity.toyhouse.ToyHouseMgr;

import java.util.ArrayList;
import java.util.List;

public class SuiTangRecycleStrategy extends AbstractItemRecycleStrategy {

    @Override
    public void markNeedRecycleItem() {
        SuiTangConfigSync config = SuiTangMgr.getConfig();
        if (config != null) {
            ActivityInfo activityInfo = config.getActivityInfo();
            long recycleTime = activityInfo.getEndTime() * 1000L + 600 * 1000;

            // 兵符回收换辎重
            List<String> bingFuParamList = new ArrayList<>();
            bingFuParamList.add(String.valueOf(config.getParamConfig().getMuBingLingItem()));
            bingFuParamList.add(String.valueOf(config.getParamConfig().getJunZiItem()));
            bingFuParamList.add("1");
            bingFuParamList.add(activityInfo.getActivityName());
            ActivityItemRecycleMgr.addRecycleItemData(config.getParamConfig().getMuBingLingItem(), activityType, 1, recycleTime, bingFuParamList);

            // 阵营宝箱清空
            for (SuiTangCampBoxConfig campBoxConfig : config.getCampBoxConfigMap().values()) {
                ActivityItemRecycleMgr.addRecycleItemData(campBoxConfig.getKey(), activityType, 2, recycleTime, new ArrayList<>());
            }
        }
    }

    @Override
    public boolean isActivityRunning() {
        SuiTangConfigSync config = SuiTangMgr.getConfig();
        return config != null && ActivityMgr.activityInTime(config.getActivityInfo());
    }

    @Override
    protected void initActivityType() {
        activityType = eActivityType.SuiTang.getValue();
    }

    @Override
    protected void doRecycle(long userId, ActivityItemRecycleData data) {
        if (data.getRecycleType() == 1) {
            item2Score(userId, data);
        } else if (data.getRecycleType() == 2) {
            int itemId = data.getItemId();
            UserBagItem userBagItem = getUserBagItem(userId, itemId);
            if (userBagItem != null && userBagItem.getNum() > 0) {
                removeItem(userBagItem);
            }
        }
    }
}
